<?php
declare (strict_types = 1);

namespace app\admin\controller;
use think\facade\Request;
use think\facade\Db;
use think\facade\View;

class Spgl
{
    public function cate()
    {

        $parentid = Request::get("id",0);
        $list = Db::name('category' )
            ->where("parentid",'=',$parentid)
            ->order("sort")
            ->select();
        View::assign("list",$list);
        $er = Db::name('category')
            ->distinct(true)
            ->column('parentid');
        View::assign("er",$er);
        return view();

    }

    public function goodAdd()
    {
        return View();
    }
//{if isset($is_down) && in_array(1,$is_down)}checked{/if}
//{eq name="is_show|default=''" value="0"}checked{/eq}
    public function goodList()
    {
        $post = Request::post();
        // 关键字搜索
        $zhi = input('post.keywords');
        $where = [];
        if (isset($zhi) && !empty($zhi))$where[] = ['ecm_goods.name','like',"%{$zhi}%"];
        // 推荐
        $zhi = input('post.butui');
        if (isset($zhi)){
            if($zhi == 1) {
                $where[] = ['ecm_goods.is_show','=',"1"];
            }
            elseif($zhi == 5){
                $where[] = ['ecm_goods.is_show','<',"5"];
            }
            else{

                $where[] = ['ecm_goods.is_show','=',"0"];
            }
        }
        // if (isset($post['is_show']) && $post['is_show'] <> '') $where[] =['is_show','=',$post[ 'is_show']];

        // 热门
        $zhi = input('post.is_hot');
        if (isset($zhi)  && !empty($zhi)){
            if($zhi == 1) {
                $where[] = ['ecm_goods.is_hot', '=', "1"];
            }
            elseif($zhi == 2){
                $where[] = ['ecm_goods.is_hot', '=', "0"];
            }
        }
        // 上架
        $zhi = input('post.is_down');
        if (isset($zhi)){
            if($zhi == 0) {
                $where[] = ['ecm_goods.is_down','=',"0"];
            }
            else{
                $where[] = ['ecm_goods.is_down','=',"1"];
            }
        }
        // 最低价格
        $zhi = input('post.di_prict');
        if (isset($zhi) && !empty($zhi))$where[] = ['ecm_goods.price_shop','>=',"$zhi"];
        // 最高价格
        $zhi = input('post.gao_prict');
        if (isset($zhi) && !empty($zhi))$where[] = ['ecm_goods.price_shop','<=',"$zhi"];
        // 开始时间
        $zhi = input('post.kaishi');
        // $zhi = strtotime($zhi)?strtotime($zhi):'';
        if (isset($zhi) && !empty($zhi))$where[] = ['ecm_goods.addtime','>=',"$zhi"];
        // 结束时间
        $zhi = input('post.jieshi');
        // $zhi = strtotime($zhi);
        if (isset($zhi) && !empty($zhi))$where[] = ['ecm_goods.addtime','<=',"$zhi"];
        $id = input('post.id');
            View::assign($post);
        $list = Db::name('goods')
            ->field('ecm_goods.*,c.name cname,c.parentid')
            ->join("ecm_category c","ecm_goods.cid=c.id",'left')
            ->where($where)
            ->select();

        View::assign('zhi',$list);

        $parentid = Request::get("id",0);
        $listd = Db::name("category")->where("parentid","=",$parentid)->order("sort")->select();

        $listb = Db::name("category")->where("parentid","<>",$parentid)->order("sort")->select();
        View::assign("listd",$listd);
        View::assign("listb",$listb);

//        $er = Db::name('category')
//            ->distinct(true)
//            ->column('parentid');
//        View::assign("er",$er);

        return View();
    }

    public function goodEdit()
    {
        return View();
    }

    public function cateEdit()
    {
        return View();
    }

    public function cateList()
    {

        $parentid=input('get.parentid');
        if(isset($parentid)&&!empty($parentid)){
            $list=Db::name('category')
                ->where('parentid','=',$parentid)
                ->order('sort','asc')
                ->select();
            View::assign('list',$list);
        }
        return View();
    }
    public function pin()
    {
        $where = [];
        $post = Request::post();
        $list=Db::name('brand')
            ->select();
        View::assign('list',$list);
// 显示
        $zhi = input('post.yshi');
        if (isset($zhi) && !empty($zhi))$where[] = ['if_show','=','1'];
        $zhiy = $zhi;
        // 隐藏
        $zhi = input('post.shi');
        if (isset($zhi) && !empty($zhi)) $where[] = ['if_show','=','0'];
        $zhim = $zhi;
        if ($zhiy == $zhim)
        {
            $where = [];
        }
        // 有图
        $zhi = input('post.ytu');
            if (isset($zhi) && !empty($zhi))$where[] = ['brand_logo','<>',""];

        // 无图
        $zhi = input('post.tu');
            if (isset($zhi) && !empty($zhi))$where[] = ['brand_logo','=',1];

        // 关键字搜索
        $zhi = input('post.keywords');

        if (isset($zhi) && !empty($zhi))$where[] = ['brand_name','like',"%{$zhi}%"];
        // 推荐
        $zhi = input('post.butui');
        if (isset($zhi)){
            if($zhi == 1) {
                $where[] = ['recommended','=',"1"];
            }
            elseif($zhi == 5){
                $where[] = ['recommended','<',"5"];
            }
            else{
                $where[] = ['recommended','=',"0"];
            }
        }

        View::assign($post);
        $list = Db::name('brand')
            ->where($where)
            ->select();
        View::assign($post);
        View::assign('zhi',$list);

        return View();
    }
}

























